package com.xgz.zhujie;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;

public class ZJTest {
    public static void main(String[] args) {
        //获取类上的注解
        Class<TUser> tUserClass = TUser.class;
        Annotation[] declaredAnnotations = tUserClass.getDeclaredAnnotations();
        for (Annotation declaredAnnotation : declaredAnnotations) {
            System.out.println("declaredAnnotation = " + declaredAnnotation);
        }
        //属性上的注解
        Field[] declaredFields = tUserClass.getDeclaredFields();
        for (Field declaredField : declaredFields) {
            Annotation[] declaredAnnotations1 = declaredField.getDeclaredAnnotations();
            for (Annotation annotation : declaredAnnotations1) {
                System.out.println("属性是：" + declaredField +"，对应的注解是： " + annotation);
                //获取对应的注解里面的属性
                //判断注解是不是@columnName的注解
                if (annotation instanceof ColumnName){
                    String value = ((ColumnName) annotation).value();
                    System.out.println("value = " + value);
                }
            }
        }
    }
}
